;$(function(){
	$(".icon_title").hover(function(){
		$(this).siblings(".icon_title_test").css("display","block");
	},function(){
		$(this).siblings(".icon_title_test").css("display","none");
	});
});
var userId = "";
if($("#head_userid").length > 0 && $("#head_userid").val().length > 0) {
	userId = "&uid="+$("#head_userid").val();
}
	
var home_url = $("#websiteRootUrl").val()+"/index.do?amount="+$("#finance_test_result").html()+userId;
var num = 0;
if(haocheLoan < tongyongLoan){
	num = tongyongLoan;
}else{
	num = haocheLoan;
}
//百度分享的代码
window._bd_share_config={
	"common":{
		"bdSnsKey":{},
		"bdText":"我在车享商城获取到价值为"+fmoney_donet(num,2,true)+"元的贷款权益，你也赶快参与看看你的额度有多少哦！",
		"bdMini":"1",
		"bdMiniList":false,
		"bdPic":imgHost+"/mall/onlinefinance/loan/haoche-result.jpg",
		"bdStyle":"0",
		"bdSize":"24",
		"bdUrl":MALL.base+"/finance/index.htm"
	},
	"share":{}
};
with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];

/*分享按钮的信息采集*/
function shareInfoCollection(code,type) {
	var info_str = code+"|"+timeStamp2String()+"|pc|"+type;
	collectionInformation(info_str);
}

/**
 * 金额格式化-带小数点的
 * @param s 数字
 * @param n 小数位数
 * @returns 格式化后的小数
 */
function fmoney_donet(s, n, _type) {  
   n = n >= 0 && n <= 20 ? n : 2;
   s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";  
   var l = s.split(".")[0].split("").reverse(),  
   r = s.split(".")[1];  
   t = "";  
   for(i = 0; i < l.length; i ++ )  
   {  
      t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");  
   }
   if(_type == false){
	   return t.split("").reverse().join("");
   } else {
	   return t.split("").reverse().join("") + "." + r;  
   }
   
}

$(function(){
	$("#finance_test_result").text(fmoney_donet(haocheLoan, 0,false));
	$("#finance_test_result1").text(fmoney_donet(tongyongLoan, 0,false));
	if(haocheFirstratio < 45){
		$("#loanMoneyFirst").val(fmoney_donet(haocheLoan*0.01*haocheFirstratio/7500, 2)+"万");
		$("#loanMoneySecond").val(fmoney_donet(haocheLoan*0.01*100/7500, 2)+"万");
	}else if(haocheFirstratio >= 45){
		$("#loanMoneyFirst").val(fmoney_donet(haocheLoan*0.01*haocheFirstratio/5500, 2)+"万");
		$("#loanMoneySecond").val(fmoney_donet(haocheLoan*0.01*100/5500, 2)+"万");
	}
});

$(function(){
	 // 领取贷金券
    $(".receive_btn").on("click",function(){
    	var con = $("#loanVoucher").html();
    	ECar.easyDialog.open({
			container : {
				header : '填写身份信息',
				content : con
			},
			success: function(){
				$(".easyDialog_footer").hide();
				var LOAN = {
					form_clause: $(".form_clause"), // 协议复选框
					id_clause: $("#formClause"), // 协议复选框
					id_agreement: $("#formAgreement"), // 协议复选框
					loan_submit_btn: $(".loan_submit_btn"), // 提交按钮
					redemptionForm: $("#redemptionForm")
				};
				
				LOAN.form_clause.on("click",function(){
					if(LOAN.id_clause.prop("checked") && LOAN.id_agreement.prop("checked")){
						LOAN.loan_submit_btn.removeClass("disable");
					}else{
						LOAN.loan_submit_btn.addClass("disable");
					}
				});
				//实时验证姓名/身份证
				var $realName = $(".realName");
				var $cardNum = $(".cardNum");
				var nameReg =  /([\u4e00-\u9fa5]|([a-zA-Z]| )+)/;
				var cardReg = /(^\d{15}$)|(^\d{17}([0-9]|X)$)/;
				function verifyName(){
					if($realName.val() == ""){
						$realName.next(".tip").text(" ");
						$realName.next(".tip").text("请输入姓名");
						$realName.next(".tip").show();
					}else if(!testName( $realName.val() )){
						//$realName.focus();
						$realName.next(".tip").text(" ");
						$realName.next(".tip").text("姓名只能是字母和汉字，请正确输入");
						$realName.next(".tip").show();
					}else{
						$realName.next(".tip").hide();
					}
				}
				function testName(name){
					var name = $.trim(name);
					var nameArray = name.split("");
					var type = true;
					for(var i = 0;i<nameArray.length;i++){
						if(!nameReg.test(nameArray[i])){
							type = false;
						}
					}
					return type;
				}
				$realName.blur(function(){
					verifyName();
				});
				function verifyCardNum(){
					if(!cardReg.test( $cardNum.val() )){
						//$cardNum.focus();
						$cardNum.next(".tip").show();
					}else{
						$cardNum.next(".tip").hide();
					}
				}
				$cardNum.blur(function(){
					verifyCardNum();
				});
				// 提交
				LOAN.loan_submit_btn.on("click",function(){
					var realName = $realName.val();
					var cardNum = $cardNum.val();
					if(!LOAN.form_clause.prop("checked")){
						return false;
					}
					var result=$("#result").val();
					if( (!nameReg.test(realName) ) || ( !cardReg.test(cardNum) ) ){
						verifyName();
						verifyCardNum();
						return false;
					}else{
						LOAN.loan_submit_btn.addClass("disable");
						$realName.next(".tip").hide();
						$cardNum.next(".tip").hide();
						$("#redemptionForm").submit();
					}
					
					// 提交数据
					var data = {};
					data.realName=realName;
					data.idCard=cardNum;
					data.result=result;
					data.voidCode=voidCode;
					data.firstPay=firstPay;
					data.loanAmountTY=tongyongLoan;
					data.firstratio = $("#firstratio").val();
					$.ajax({
						url: "/finance/redemption.htm",
						data: data,
						type:"post",
						dataType:"json",
						success: function(code){
							var count = "";
							var codes = code.retCode;
							if("0000" == codes || "1" == codes || "2" == codes|| "3" == codes){
								$("#price").val($("#loanMoneySecond").val());
								$("#ticketed").submit();
							}else if("-4" == codes){
								ECar.easyDialog.open({
									  container : {
									    header : '提示信息',
									    content : '<div style="text-align:center;width:380px;">'+code.retMsg+'</div>',
									    yesFn : function(){
									    	window.location.href = "/member/myLoan.htm";
										},
										noFn : function(){
											return;
										},
										yesText : '查看权益',	
										noText : '取消'
									  }
									});
							}else{
								ECar.easyDialog.open({
								  container : {
								    header : '提示信息',
								    content : '<div style="text-align:center;width:380px;">'+code.retMsg+'</div>'
								  }
								});
								return false;
							}
							LOAN.loan_submit_btn.removeClass("disable");
						}
					});
				});
				
			}
		});
    });
});